<template>
	<view class="content">
		<view class="text-center" style="margin-top: 40%;" v-if="loading">
			<view class="text-xsl" >
				<text class="cuIcon cuIcon-icloading cuIconfont-spin text-progress" ></text>
			</view>
			<view class="margin-top-sm text-brown" v-if="type!='load'">
				确认中,请稍等...
			</view>
			<view class="margin-top-sm text-brown" v-else>
				<button class="cu-btn bg-red margin-sm lg shadow bg-orange" @tap="getresult">查询</button>
			</view>
		</view>
		<view class="text-center" style="margin-top: 40%;" v-else>
			<view class="text-xsl">
				<text class="cuIcon cuIcon-roundcheck text-green" v-if="isok==1"></text>
				<text class="cuIcon cuIcon-roundclose text-orange" v-else></text>
			</view>
			<view class="">
				{{textstr}}
			</view>
			<view class="text-sm text-gray margin-top-xs">
				{{num}}秒后跳转到<text class="text-brown" @tap="gohome">首页</text> 
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				order:null,
				loading:true,
				textstr:"认证成功",
				isok:1,
				num:10,
				type:null
			}
		},
		onLoad(ops) {
			if(ops.type!="" && ops.type!=null && ops.type!=undefined){
				this.type=ops.type
			}
			if(ops.order!="" && ops.order!=null && ops.order!=undefined){
				console.log(ops)
				this.order=ops.order
				if(this.type!="load"){
					this.getresult()
				}
			}else{
				uni.showToast({
					title:'接收数据错误',
					position: 'bottom',
					icon:"error"
				})
			}
		},
		methods: {
			gohome(){
				uni.navigateTo({
					url: 'index',
				});
			},
			timeover(){
				let time=5
				var that=this
				var intime=setInterval(function(){
					time--
					that.num=time
					if(time<=0){
						clearInterval(intime)
						uni.navigateTo({
							url: "index",
						});
					}
				},1000)
			},
			getresult(){
				var that=this
				uni.request({
					method:"post",
					url: that.app.apiHost+"/faceback",
					data:{order:that.order},
					header:{'Authorization':''},
					success:(data)=>{
						console.log(data);
						that.loading=false
						if(data.data.code==0){
							that.isok=1
							that.textstr="认证成功"
							that.timeover()
						}else if(data.data.code==2){
							that.textstr=data.data.msg
						}else{
							that.isok=0
							that.textstr=data.data.msg
							that.timeover()
						}
					},
					fail(a) {
						uni.showToast({
							title:'链接失败',
							position: 'bottom',
							icon:'error'
						}) 
					}
				})
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

</style>
